925. Long Pressed Name - LeetCode Solution


Two Pointers String

Python Code:

class Solution:
    def isLongPressedName(self, name: str, typed: str) -> bool:
        
        if len(typed) < len(name):
            return False
        
        
        a = []
        b = []
        last = name[0]   
        flag = 0
        
        count = 0
        for i in range(len(name)):
            if name[i] == last:
                count+=1
                flag = 0
            else:
                a.append([count, last])
                count = 1
                last = name[i]
                flag = 1
  
        a.append([count, last])
 
        
        last = typed[0]   
        flag = 0
        
        count = 0
        for i in range(len(typed)):
            if typed[i] == last:
                count+=1
                flag = 0
            else:
                b.append([count, last])
                count = 1
                last = typed[i]
                flag = 1
                

        b.append([count, last])
    
        if len(b) !=len(a):
            return False
        
        for i in range(len(a)):
            if a[i][1] == b[i][1]:
                if b[i][0] >= a[i][0]:
                    continue
                else:
                    return False
            else:
                return False
        
        return True
                

            
        
        
        


Comments

Submit
0 Comments
More Questions

908A - New Year and Counting Cards
146A - Lucky Ticket
1594C - Make Them Equal
1676A - Lucky
1700B - Palindromic Numbers
702C - Cellular Network
1672C - Unequal Array
1706C - Qpwoeirut And The City
1697A - Parkway Walk
1505B - DMCA
478B - Random Teams
1705C - Mark and His Unfinished Essay
1401C - Mere Array
1613B - Absent Remainder
1536B - Prinzessin der Verurteilung
1699B - Almost Ternary Matrix
1545A - AquaMoon and Strange Sort
538B - Quasi Binary
424A - Squats
1703A - YES or YES
494A - Treasure
48B - Land Lot
835A - Key races
1622C - Set or Decrease
1682A - Palindromic Indices
903C - Boxes Packing
887A - Div 64
755B - PolandBall and Game
808B - Average Sleep Time
1515E - Phoenix and Computers